#!/usr/bin/env python3

import sys

sys.path.append("../lib")

from spread_sheet import Spreadsheet
from rich import print as rprint


FILES = sys.argv[1:]

rprint(FILES)

DIFF_AREA = "A6:AJ18"


def usage():
    print("""
python3 compare-two.py a.xlsx b.xlsx
""")


def get_last_two():
    return FILES[-2:]


def diff_all():
    for i in range(len(FILES) - 1):
        old_file = FILES[i]
        new_file = FILES[i + 1]
        rprint("Diff", old_file, "VS", new_file)
        diff_two(old_file, new_file, DIFF_AREA)


def diff_two(old_file, new_file, range_str, modify=False):
    old_spreadsheet = Spreadsheet(old_file)
    new_spreadsheet = Spreadsheet(new_file)

    if modify:
        single_mod_cells = old_spreadsheet.diff(new_spreadsheet, range_str=range_str)
    else:
        single_mod_cells = old_spreadsheet.dry_diff(
            new_spreadsheet, range_str=range_str
        )

    rprint("Changes", single_mod_cells)
    print("-------------------------------------")


def main():
    old_file, new_file = get_last_two()
    diff_two(old_file, new_file, DIFF_AREA)

    # diff_all()

    pass


if __name__ == "__main__":
    main()
